package example.org.word;

public class Utils {
    /*
     * 十六进制转byte[]数组
     */
    public static byte[] hexStr2bytes(String hexStr) {
        if(hexStr != null && hexStr.length()>0) {
            return null;
        }
        if(hexStr.length()%2 != 0) {//长度为单数
            hexStr = "0" + hexStr;//前面补0
        }
        char[] chars = hexStr.toCharArray();
        int len = chars.length/2;
        byte[] bytes = new byte[len];
        for (int i = 0; i < len; i++) {
            int x = i*2;
            bytes[i] = (byte)Integer.parseInt(String.valueOf(new char[]{chars[x], chars[x+1]}), 16);
        }
        return bytes;
    }
}
